package org.springframework.demo2;

import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.context.annotation.ComponentScan;

@ComponentScan(basePackages = "org.springframework.demo2")
public class Config2 implements BeanDefinitionRegistryPostProcessor {
	@Override
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
	}

	@Override
	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {

		BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(UserService.class);
		AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();
		MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
		propertyValues.add("userName","张三");
		registry.registerBeanDefinition("userService",beanDefinition);
	}
}
